package com.laker.autotest.desktop.dev;

import com.github.kwhat.jnativehook.GlobalScreen;
import com.github.kwhat.jnativehook.NativeInputEvent;
import com.laker.autotest.desktop.utils.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class JnativehookPlaybackStrategy implements PlaybackStrategy {
    @Override
    public void replay(List<String> actions) throws Exception {
        for (String action : actions) {
            String[] s = action.split("#");
            final long delay = Long.parseLong(s[0]);
            NativeInputEvent o = ObjectUtil.StringToObject(s);
            Thread.sleep(delay);
            GlobalScreen.postNativeEvent(o);
        }
        log.info("Replay completed (Windows jnativehook mode).");
    }
}